<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class gif extends CI_Controller {
	
	var $theme_data = array(
	'layout_main' => 'frontend/layout',
	'left' => 'frontend/include/left',
	'right' => 'frontend/include/right',
    );

	
	public function __construct(){
		parent::__construct();
		$this->load->model("mcategory");
		$this->load->model("mgif");
	}
	
	public function index() {
		
		$gif = $this->mgif->get_last();
		if ($gif) {
			return redirect(gif_url($gif->gif_id));
		}
		return redirect(page404());
	}
	
	public function view($id){
		$id = (int) $id;
		$data = array();
		$data['gif'] = $this->mgif->get($id, $this->mgif->primaryKey);
		if (empty($data['gif'])) {
			return redirect(page404());
		}
		$data['gif_next'] = $this->mgif->get_next($data['gif']->gif_id);
		$data['gif_prev'] = $this->mgif->get_prev($data['gif']->gif_id);
		$data['seo'] = array('title' => "View gif " . $id);
        $this->theme_data["main"] = "frontend/".__CLASS__
		."/".__FUNCTION__;
        $this->template->view($this->theme_data, $data);
	}
	public function get_next($id) {
		if (!$this->input->is_ajax())
			exit('No direct script access allowed');
			
		$id = (int) $id;
		if($id > 0) {
			$this->mgif->get_next($id);
		}
		exit('No direct script access allowed');
	}
	
	public function get_prev($id) {
		if (!$this->input->is_ajax())
			exit('No direct script access allowed');
			
		$id = (int) $id;
		if($id > 0) {
			$this->mgif->get_prev($id);
		}
		exit('No direct script access allowed');
	}
	
	
}